const Router = require('koa-router')
const remind = new Router()
//！拿到前端的数据
//数据库连接池
const pg = require('pg');
let psql = new pg.Pool({
    database: 'running',
    user: 'run',
    port: 5432,
    host: '82.157.94.115',
    password: 'z12345678',
    max: 2
  })

remind.get('/alarm', async ctx => {
    let {obj1,obj2,obj3,index1,index2,index3,switch1Checked,switch2Checked,switch3Checked} = ctx.request.body;
    console.log("obj1",obj1)
    let insertContentPostgresql = `insert into remind (obj1,obj2,obj3,index1,index2,index3,switch1Checked,switch2Checked,switch3Checked) values ('${obj1}','${obj2}', '${obj3}', '${index1}', '${index2}, '${index3}', '${switch1Checked}', '${switch2Checked}, '${switch3Checked}')`;
    let content = await psql.query(insertContentPostgresql);

    if (content.rowCount > 0)
        ctx.body = {
            obj1: obj1,
            obj2: obj2,
            obj3: obj3, 
            index1: index1,
            index2: index2,
            index3: index3,
            switch1Checked: switch1Checked,
            switch2Checked: switch2Checked,
            switch3Checked: switch3Checked
            
        };
})

module.exports = remind